package com.z.dao.impl;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

import com.z.dao.BaseDao;

public class BaseDaoImpl implements BaseDao {

	public  Connection conn;
	PreparedStatement ps;
	ResultSet resultSet;
	int result;
	public Connection getConnection() {
		try {
			Properties properties = new Properties();
			InputStream inputStream = BaseDaoImpl.class.getClassLoader()
					.getResourceAsStream("jdbc.properties");
			properties.load(inputStream);
			Class.forName(properties.getProperty("driver"));
			conn=DriverManager.getConnection(properties.getProperty("connectionString"),properties.getProperty("username")
					,properties.getProperty("password"));
			
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	public void closeConnection(Connection connection,ResultSet resultSet,
			PreparedStatement preparedStatement) throws SQLException {
		if(connection!=null){
				connection.close();
		}
		if(resultSet!=null){
			resultSet.close();
		}
		if(preparedStatement!=null){
			preparedStatement.close();
		}
	}
	public static void main(String[] args) {
		BaseDao bd=new BaseDaoImpl();
		try {
			bd.getConnection().createStatement();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
